﻿import { Component, Injector, ViewChild, ViewEncapsulation, OnInit, AfterViewInit } from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import { PipelineServiceProxy, PipelineAndActsListDto } from '@shared/service-proxies/service-proxies';
import { Paginator } from 'primeng/components/paginator/paginator';
import { LazyLoadEvent } from 'primeng/primeng';

@Component({
  templateUrl: './flex.component.html',
  styleUrls: ['./flex.component.less'],
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()]
})

export class FlexsComponent extends AppComponentBase implements OnInit {

  @ViewChild('paginator') paginator: Paginator;

  filterText = '';
  className1 = 'active';
  className2 = '';
  className3 = '';
  status = '进行';
  pipes = new Array<PipelineAndActsListDto>();

  constructor(
    injector: Injector,
    private _pipelineService: PipelineServiceProxy,
  ) {
    super(injector);
  }

  ngOnInit(): void {
    this.getPipes();
  }

  getPipes(event?: LazyLoadEvent) {
    if (this.primengTableHelper.shouldResetPaging(event)) {
      this.paginator.changePage(0);
      return;
    }

    this.primengTableHelper.showLoadingIndicator();

    this._pipelineService.getPipelinesAndActs(
      this.filterText,
      1,
      '58',
      undefined,
      this.status,
      undefined,
      1000,
      this.primengTableHelper.getSkipCount(this.paginator, event)
    )
      .subscribe(result => {
        this.primengTableHelper.totalRecordsCount = result.totalCount;
        this.pipes = result.items;
        this.primengTableHelper.hideLoadingIndicator();
      });
  }
  tabTypeClick(tab: Number) {
    if (tab === 1) {
      this.className1 = 'active';
      this.className2 = '';
      this.className3 = '';
      this.status = '进行';
    } else if (tab === 2) {
      this.className1 = '';
      this.className2 = '';
      this.className3 = '';
      this.status = '完成';
    }
    this.getPipes();
  }

}
